﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace mamnontuoitho7.AppCode
{
    public class Link
    {
        public ConnectGetData _connectData;
        public Link()
        {
            _connectData = new ConnectGetData();
        }

        /// <summary>
        /// Insert record into table ShareLink
        /// </summary>
        /// <param name="linkName"></param>
        /// <param name="linkWeb"></param>
        internal void ShareLinkCreate(String linkName, String linkWeb)
        {
            SqlConnection con = _connectData.GetConnect();
            SqlCommand cmd = new SqlCommand("Insert into ShareLink(LinkName, LinkWeb) values(@linkName, @linkWeb)", con);
            cmd.Parameters.AddWithValue("@linkName", linkName);
            cmd.Parameters.AddWithValue("@linkWeb", linkWeb);

            con.Open();
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            con.Close();
        }

        /// <summary>
        /// Get all share link
        /// </summary>
        /// <returns></returns>
        internal DataTable GetAllShareLink()
        {
            SqlConnection con = _connectData.GetConnect();
            string sqlUp = "select * from ShareLink ";
            SqlCommand cmd = new SqlCommand(sqlUp, con);

            return _connectData.GetDataTable(cmd);
        }


        /// <summary>
        /// Delete Share Link
        /// </summary>
        /// <param name="p"></param>
        internal void DeleteShareLink(String shareLinkID)
        {
            SqlConnection con = _connectData.GetConnect();
            SqlCommand cmd = new SqlCommand("Delete ShareLink where ShareLinkID = @shareLinkID", con);
            cmd.Parameters.AddWithValue("@shareLinkID", shareLinkID);

            con.Open();
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            con.Close();
        }
    }
}